package com.deng.mail.mailorder.service.impl;

import com.deng.mail.mailorder.entity.OrderEntity;
import com.deng.mail.mailorder.entity.OrderReturnReasonEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deng.common.utils.PageUtils;
import com.deng.common.utils.Query;

import com.deng.mail.mailorder.dao.OrderItemDao;
import com.deng.mail.mailorder.entity.OrderItemEntity;
import com.deng.mail.mailorder.service.OrderItemService;


@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * queues：声明需要监听的队列
     * channel：当前传输数据的通道
     *
     * queue: 可以很多人来监听，只要收到消息，队列删除消息，而且只能有一个收到此消息
     * 1.订单服务启动多个，同一个消息，只能有一个客户端收到
     * 2.只有一个消息完全处理完，方法运行结束，我们就可以接收到下一个消息
     */
    @RabbitListener(queues = {"hello-java-queue"})
    public void revieveMessage(Message message,
                               OrderReturnReasonEntity content, Channel channel) {
        //拿到主体内容
        byte[] body = message.getBody();
        //拿到的消息头属性信息
        MessageProperties messageProperties = message.getMessageProperties();
        System.out.println("接受到的消息...内容" + message + "===内容：" + content);

    }

    @RabbitHandler
    public void revieveMessage2(Message message,
                               OrderReturnReasonEntity content, Channel channel) {
        //拿到主体内容
        byte[] body = message.getBody();
        //拿到的消息头属性信息
        MessageProperties messageProperties = message.getMessageProperties();
        System.out.println("接受到的消息...内容" + message + "===内容：" + content);

    }

    @RabbitHandler
    public void revieveMessage3(OrderEntity content) {
        //拿到主体内容
//        byte[] body = message.getBody();
//        //拿到的消息头属性信息
//        MessageProperties messageProperties = message.getMessageProperties();
//        System.out.println("接受到的消息...内容" + message + "===内容：" + content);

    }

}